#include "sct/rtspserver/aacstreamsource.h"

namespace sct
{
using namespace std;

CAACStreamSource::CAACStreamSource(CServerInterface * server):
				CStreamSource(server)
{
	setName(sct::toString("CAACStreamSource %p", this));
}

CAACStreamSource::~CAACStreamSource()
{
	;
}


void CAACStreamSource::onPutData(const void*p, const int len, const int64_t pts)
{
	///split adts stream to adts frame
	uint8_t * pCur;
	int left;

	pCur = (uint8_t*)p;
	left = len;

	unsigned char headers[7];
	u_int16_t frame_length;

//	int cnt = 0;

	while(left > 0)
	{
//		cnt++;

		memcpy(headers, pCur, sizeof(headers));
		frame_length
			    = ((headers[3]&0x03)<<11) | (headers[4]<<3) | ((headers[5]&0xE0)>>5);


		CStreamSource::onPutData(pCur, frame_length, pts);

		pCur += frame_length;
		left -= frame_length;
	}

	if(0 != left)
	{
		SCT_LOGD();
	}

//	SCT_LOG("aac block split to %d frames", cnt);
}

}
